// cc MaxTemperatureWithCombiner Application to find the maximum temperature, using a combiner function for efficiency

import lombok.extern.slf4j.Slf4j;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

@Slf4j
// vv MaxTemperatureWithCombiner
public class MaxTemperatureWithCombiner {

    // 测试数据在目录/Users/sunchuanfu/IdeaProjects/hadoop-book/input/ncdc/sample.txt
    // main方法多个参数以空格分隔
    public static void main(String[] args) throws Exception {
        if (args.length != 2) {
            System.err.println("Usage: MaxTemperatureWithCombiner <input path> <output path>");
            System.exit(-1);
        }

        Job job = new Job();// 定义作业规范
        job.setJarByClass(MaxTemperatureWithCombiner.class);// Hadoop上执行的jar包，通过类名会找到包含此类的jar包
        job.setJobName("Max temperature");

        FileInputFormat.addInputPath(job, new Path(args[0]));// 输入输出路径
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        job.setMapperClass(MaxTemperatureMapper.class);// 指定map类型
        /*[*/
        job.setCombinerClass(MaxTemperatureReducer.class)/*]*/;
        job.setReducerClass(MaxTemperatureReducer.class);// 指定reduce类型

        job.setOutputKeyClass(Text.class);// 输出的key和value类型
        job.setOutputValueClass(IntWritable.class);

        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
// ^^ MaxTemperatureWithCombiner
